<?php
/**
* PHP Template.
*/
class ContactModel extends Model {
	 public function __construct() {
			 parent::Model();
		 }
	 public function create($cDataArray) {
			 $c_id = -1; // by default, -1
			 $queryData = array(
				 $cDataArray["phone"],
				 $cDataArray["cell"],
				 $cDataArray["fax"],
				 $cDataArray["email"],
				 $cDataArray["best_time"],
				 $cDataArray["best_days"]
				 );
			 $this->db->query("INSERT INTO contact (phone,cell,fax,email,best_time,best_days) VALUES(?,?,?,?,?,?)",$queryData);
			 $rs = $this->db->query("SELECT LAST_INSERT_ID() as contact_id FROM contact");
			 if($rs->num_rows()>0){
					 $c_id = $rs->row()->contact_id;
				 }
			 return $c_id; // return contact ID created
		 }
		 /**
		 * returns true on success
		 */
	 public function update($cDataArray,$c_id) {
			 $queryData = array(
				 $cDataArray["phone"],
				 $cDataArray["cell"],
				 $cDataArray["fax"],
				 $cDataArray["email"],
				 $cDataArray["best_time"],
				 $cDataArray["best_days"],
				 $c_id
				 );
			 $this->db->query("UPDATE contact SET phone=?,cell=?,fax=?,email=?,best_time=?,best_days=? WHERE contact_id=?",$queryData);
			 $rs = $this->db->query("SELECT LAST_INSERT_ID() as contact_id FROM contact");
			 return ($rs->num_rows()>0);
		 }
	 public function getContact($cId) {
			 return null;
		 }
}
?>
